home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / utils / file / managers / mc-3.2 / mc-3 / mc-3.2.1 / src / option.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-05-17  |  6.0 KB  |  211 lines

  1. /* Configure box module for the Midnight Commander
  2.    Copyright (C) 1994 Radek Doulik
  3.  
  4.    This program is free software; you can redistribute it and/or modify
  5.    it under the terms of the GNU General Public License as published by
  6.    the Free Software Foundation; either version 2 of the License, or
  7.    (at your option) any later version.
  8.  
  9.    This program is distributed in the hope that it will be useful,
  10.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12.    GNU General Public License for more details.
  13.  
  14.    You should have received a copy of the GNU General Public License
  15.    along with this program; if not, write to the Free Software
  16.    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  
  17.  */
  18.  
  19. #include <config.h>
  20. #include <string.h>
  21. #include <stdio.h>
  22. /* Needed for the extern declarations of integer parameters */
  23. #include <sys/types.h>
  24. #include <sys/param.h>
  25. #include <sys/stat.h>
  26. #ifdef HAVE_UNISTD_H
  27. #   include <unistd.h>
  28. #endif
  29. #include "tty.h"
  30. #include "mad.h"
  31. #include "util.h"
  32. #include "win.h"
  33. #include "color.h"
  34. #include "dlg.h"
  35. #include "widget.h"
  36. #include "setup.h"        /* For save_setup() */
  37. #include "dialog.h"        /* For do_refresh() */
  38. #include "main.h"
  39. #include "profile.h"        /* For sync_profiles */
  40.  
  41. #include "dir.h"
  42. #include "panel.h"        /* Needed for the externs */
  43. #include "file.h"
  44. #include "layout.h"        /* For nice_rotating_dash */
  45. #define PX    5
  46. #define PY    2
  47.  
  48. #define RX      5
  49. #define RY      10
  50.  
  51. #define CX    5
  52. #define CY    2
  53.  
  54. #define BX    15
  55. #define BY    15
  56.  
  57. #define OX    34
  58. #define OY    2
  59.  
  60. #define TX    36
  61. #define TY    11
  62.  
  63.  
  64. static Dlg_head *conf_dlg;
  65.  
  66. static int r_but;
  67.  
  68. #define TOGGLE_VARIABLE 0
  69.  
  70. static struct {
  71.     char   *text;
  72.     int    *variable;
  73.     void   (*toggle_function)(void);
  74.     WCheck *widget;
  75.     int    hkey;
  76.     int    hpos;
  77. } check_options [] = {
  78.    {"safe deLete",       &know_what_am_i_doing, TOGGLE_VARIABLE,    0,'l', 7 },
  79.    {"cd follows linKs",  &cd_symlinks,       TOGGLE_VARIABLE,       0,'k',14 },
  80.    {"advanced choWn",    &advanced_chfns,    TOGGLE_VARIABLE,       0,'w',12 },
  81.    {"lYnx-like motion",  &navigate_with_arrows,TOGGLE_VARIABLE,     0,'y', 1 },
  82.    {"Rotating dash",     &nice_rotating_dash,TOGGLE_VARIABLE,       0,'r', 0 },
  83.    {"Complete: show all",&show_all_if_ambiguous,TOGGLE_VARIABLE,    0,'c', 0 },
  84.    {"Use internal view", &use_internal_view, TOGGLE_VARIABLE,       0,'u', 0 },
  85.    {"auto mEnus",        &auto_menu,         TOGGLE_VARIABLE,       0,'e', 6 },
  86.    {"Auto save setup",   &auto_save_setup,   TOGGLE_VARIABLE,       0,'a', 0 },
  87.    {"shell Patterns",    &easy_patterns,     TOGGLE_VARIABLE,       0,'p', 6 },
  88.    {"Verbose operation", &verbose,           TOGGLE_VARIABLE,       0,'v', 0 },
  89.    {"Fast dir reload",   &fast_reload,       toggle_fast_reload,    0,'f', 0 },
  90.    {"miX all files",     &mix_all_files,     toggle_mix_all_files,  0,'x', 2 },
  91.    {"Drop down menus",   &drop_menus,        TOGGLE_VARIABLE,       0,'d', 0 },
  92.    {"Mark moves down",   &mark_moves_down,   TOGGLE_VARIABLE,       0,'m', 0 },
  93.    {"show Hidden files", &show_dot_files,    toggle_show_hidden,    0,'h', 5 },
  94.    {"show Backup files", &show_backups,      toggle_show_backup,    0,'b', 5 },
  95.    { 0, 0, 0, 0 }
  96. };
  97.  
  98. static WRadio *pause_radio;
  99.  
  100. static char *pause_options [3] = {
  101.     "Never",
  102.     "on dumb Terminals",
  103.     "alwaYs" };
  104.  
  105. static int configure_callback (struct Dlg_head *h, int Id, int Msg)
  106. {
  107.     switch (Msg) {
  108.     case DLG_DRAW:
  109.     attrset (REVERSE_COLOR);
  110.     dlg_erase (h);
  111.     
  112.     draw_box (h, 1, 2, 16, 62);
  113.     draw_box (h, PY, PX, 8, 27);
  114.     draw_box (h, OY, OX, 13, 27);
  115.     draw_box (h, RY, RX, 5, 27);
  116.     break;
  117.  
  118.     case DLG_END:
  119.     r_but = Id;
  120.     break;
  121.     }
  122.     return 0;
  123. }
  124.  
  125. static void init_configure (void)
  126. {
  127.     int i;
  128.  
  129.     conf_dlg = create_dlg (0, 0, 18, 66, dialog_colors,
  130.                configure_callback, "[Options Menu]",
  131.                "option", DLG_CENTER);
  132.     x_set_dialog_title (conf_dlg, "Configure options");
  133.  
  134.     tk_new_frame (conf_dlg, "b.");
  135.     add_widgetl (conf_dlg,
  136.     button_new (BY, BX+26, B_CANCEL, "[ Cancel ]",'c',2, 0, 0),
  137.     XV_WLAY_RIGHTOF);
  138.  
  139.     add_widgetl (conf_dlg,
  140.     button_new (BY, BX+12, B_EXIT,   "[ Save ]",'s',2, 0, 0),
  141.     XV_WLAY_RIGHTOF);
  142.     
  143.     add_widgetl (conf_dlg,
  144.         button_new (BY, BX,    B_ENTER,  "[[ Ok ]]",'o',3, 0, 0),
  145.         XV_WLAY_CENTERROW);
  146.  
  147. #define XTRACT(i) *check_options[i].variable, check_options[i].text, check_options[i].hkey, check_options[i].hpos
  148.  
  149.     tk_new_frame (conf_dlg, "c.");
  150.     /* Add all the checkboxes */
  151.     for (i = 0; i < 11; i++){
  152.     check_options [i].widget = check_new (OY + (11-i), OX+2, XTRACT(i));
  153.     add_widgetl (conf_dlg, check_options [i].widget,
  154.         XV_WLAY_BELOWCLOSE);
  155.     }
  156.  
  157.     tk_new_frame (conf_dlg, "o.");
  158.     add_widgetl (conf_dlg, label_new (OY, OX + 1, "Other options"),
  159.         XV_WLAY_NEXTCOLUMN);
  160.  
  161.     tk_new_frame (conf_dlg, "p.");
  162.     pause_radio = radio_new (RY+1, RX+1, 3, pause_options, 1);
  163.     pause_radio->sel = pause_after_run;
  164.     add_widgetl (conf_dlg, pause_radio, XV_WLAY_BELOWCLOSE);
  165.  
  166.     add_widgetl (conf_dlg, label_new (RY, RX + 1, "Pause after run..."),
  167.         XV_WLAY_BELOWOF);
  168.  
  169.     tk_frame (conf_dlg, "o.");
  170.     for (i = 0; i < 6; i++){
  171.     check_options [i+11].widget = check_new (PY + (6-i), PX+2,
  172.                           XTRACT(i+11));
  173.     add_widgetl (conf_dlg, check_options [i+11].widget,
  174.         XV_WLAY_BELOWCLOSE);
  175.     }
  176.     tk_frame (conf_dlg, "c.");
  177.     add_widgetl (conf_dlg, label_new (PY, PX + 1, "Panel options"),
  178.         XV_WLAY_NEXTCOLUMN);
  179.     tk_end_frame ();
  180. }
  181.  
  182.  
  183. void configure_box (void)
  184. {
  185.     int result, i;
  186.     
  187.     init_configure ();
  188.     run_dlg (conf_dlg);
  189.  
  190.     result = conf_dlg->ret_value;
  191.     if (result == B_ENTER || result == B_EXIT){
  192.     for (i = 0; check_options [i].text; i++)
  193.         if (check_options [i].widget->state & C_CHANGE){
  194.         if (check_options [i].toggle_function)
  195.             (*check_options [i].toggle_function)();
  196.         else
  197.             *check_options [i].variable =
  198.             !(*check_options [i].variable);
  199.         }
  200.     pause_after_run = pause_radio->sel;
  201.     }
  202.  
  203.     /* If they pressed the save button */
  204.     if (result == B_EXIT){
  205.     save_configure ();
  206.     sync_profiles ();
  207.     }
  208.  
  209.     destroy_dlg (conf_dlg);
  210. }
  211.